Skip to content

Conversation

Aniketsy
Copy link
Contributor

This PR resolves (GH#62158) by removing the legacy special-casing for Python date objects in DatetimeIndex indexing logic.

What’s Changed:
Removed the special-case handling of date objects in DatetimeIndex.getitem.

Updated/added tests in pandas/tests/frame/indexing/test_indexing.py to reflect the new, consistent behavior.

Please let me know if my approach or fix needs any improvements . I’m open to feedback and happy to make changes based on suggestions.
Thankyou !

@Aniketsy
Copy link
Contributor Author

@jbrockmendel hi
Could you please review my PR for the datetime/date indexing deprecation?

I have a question about handling the new deprecation warning
Do I need to add @pytest.mark.filterwarnings("ignore:Indexing/slicing with datetime.date is deprecated") to every individual test that triggers this warning, or is there a preferred way to handle this globally for the test suite?
Also should I update every test that uses the deprecated behavior, or is there a more efficient approach?

Thanks!

@@ -629,7 +629,13 @@ def get_loc(self, key):
def _maybe_cast_slice_bound(self, label, side: str):
# GH#42855 handle date here instead of get_slice_bound
if isinstance(label, dt.date) and not isinstance(label, dt.datetime):
# Pandas supports slicing with dates, treated as datetimes at midnight.
warnings.warn(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think this is part of the original issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feedback. I have removed the unrelated parts of this issue, and I will look into it further as the checks are still failing.

dti = Index(ser3)
# All should be consistent
assert dti.get_loc(ser[0]) == 0
tm.assert_numpy_array_equal(dti.get_indexer(ser.values), [0])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the second arg here should be an array, not list

@@ -190,7 +190,7 @@ def test_asfreq_with_date_object_index(self, frame_or_series):
ts = frame_or_series(np.random.default_rng(2).standard_normal(20), index=rng)

ts2 = ts.copy()
ts2.index = [x.date() for x in ts2.index]
ts2.index = to_datetime([x.date() for x in ts2.index])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this defeats the purpose of this test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants